import { INCREMENT, DECREMENT, ADDODD, ADDASYNC } from "../constant";
const initState = 0
export default function countReducer(prevState = initState, action) {
  const { type, value } = action
  let newState = prevState
  switch (type) {
    case INCREMENT:
      newState = prevState + value
      break;
    case DECREMENT:
      newState = prevState - value
      break;
    case ADDODD:
      if (prevState % 2 !== 0) {
        newState = prevState + value
      }
      break;
    // case ADDASYNC:
    //   setTimeout(() => {
    //     newState = prevState + value
    //     console.log('setTimeout newState', newState)
    //   }, 1000);
    //   break;
    default:
      break;
  }
  console.log('newState', newState)
  return newState
}